package middle

import (
	"github.com/gin-gonic/gin"
	"ylm.sl/common/biz"
	"ylm.sl/common/enums"
)

// 用户信息传输
func UserTransmitFilter() gin.HandlerFunc {
	return func(c *gin.Context) {
		username := c.Request.Header.Get(enums.UserName)
		if username != "" {
			userId := c.MustGet(enums.UserID).(uint64)
			realName := c.Request.Header.Get(enums.RealName)

			c.Set(enums.UserContext, &biz.UserInfoDTO{
				UserId:   userId,
				Username: username,
				RealName: realName,
			})
		} else {
			c.Abort()
			return
		}
		c.Next()
	}
}
